package com.example.replacebooks.controller;


import com.example.replacebooks.common.Result;
import com.example.replacebooks.entity.Changebook;
import com.example.replacebooks.entity.Params;
import com.example.replacebooks.service.ChangbookService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 书籍信息表 前端控制器
 * </p>
 *
 * @author replacebooks
 * @since 2024-12-15
 */
@RestController
@RequestMapping("/changebook")
public class ChangebookController {
    @Resource
    private ChangbookService changbookService;

    @PostMapping("/add")
    public Result add(@RequestBody Changebook changebook){
        changbookService.add(changebook);
        return Result.success();
    }

    @PostMapping("/addaddress")
    public Result addAddress(@RequestBody Changebook changebook){
        changbookService.addAddress(changebook);
        return Result.success();
    }

    @PostMapping("/savestatu")
    public Result savestatu(@RequestBody Changebook changebook){
        changbookService.savestatu(changebook);
        return Result.success();
    }

    @GetMapping("/{bookid}")
    public Result findByBookid(@PathVariable Integer changebookid){
        Changebook list = changbookService.findByBookid(changebookid);
        return Result.success(list);
    }

    @GetMapping("/search")
    public Result findBySearch(Params params){
        PageInfo<Changebook> info = changbookService.findBySearch(params);
        return Result.success(info);
    }

    @GetMapping("/statusearch")
    public Result findByStaueSearch(Params params){
        PageInfo<Changebook> info = changbookService.findByStatuSearch(params);
        return Result.success(info);
    }

    @DeleteMapping("/{changebookid}")
    public Result delete(@PathVariable Integer changebookid){
        changbookService.delete(changebookid);
        return Result.success();
    }
}
